<?php
include 'dbconfig.php'; 
mysql_select_db($db, $con);

if (isset($_POST['coursename'])) {
	$strSearchVal = mysql_real_escape_string($_POST['coursename']);
	$hash = mysql_real_escape_string($_POST['hash']);
} else 
    $strSearchVal="";


//$query = 'SELECT * FROM course_templates JOIN course_instances ON (course_templates.cid=course_instances.cid) WHERE (Name LIKE \'%'. $strSearchVal . '%\')';
$query = 'SELECT * FROM course_templates WHERE (Name LIKE \'%'. $strSearchVal . '%\') ORDER BY comp DESC';
$result = mysql_query($query);

echo "<ul>";
while ($arrThisRow = mysql_fetch_array($result)) {
	echo '<li id="'.$arrThisRow['cid'].';'.$hash.'">' . $arrThisRow['name'] .'<br><i class="informal">'.$arrThisRow['cid'].'</i></li>';
}
echo "</ul>";

mysql_close($con);

?>